﻿
using Rio.Framework.Localisation;
using Rio.Framework.Pages;
using Rio.Manager.Application.ViewModel.Administration;
using Rio.Manager.Application.Model;
using System;
using System.Windows.Controls;

namespace Rio.Manager.Application.Views
{
    public partial class GroupSynchronizationTabView : UserControl
    {
        #region Constructors

        public GroupSynchronizationTabView()
        {
            InitializeComponent();
        }

        #endregion Constructors

        #region Event

        /// <summary>Change Last Name value.</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cbb_LastName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Value to test.
            string l_sValueTest = (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLastName;

            //Value selected test.
            if (l_sValueTest != string.Empty) 
            {
                if (l_sValueTest != null)
                {
                    if (((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnFirstName == l_sValueTest) ||
                               ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLogin == l_sValueTest) ||
                               ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnMail == l_sValueTest))
                    {
                        //Value non unique.
                        (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLastName = string.Empty;

                        //User message.
                        MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow(String.Empty, string.Format(Resx.GetLabel(ResxRioManagerGroup.GROUP_MSG_CORRESPONDENCE_AD_RIO_COLUMN_USE), l_sValueTest), MessageBoxButtons.Ok, MessageBoxIcon.Error);
                        L_oMessage.Show();
                    }  
                }                 
            }           
        }

        /// <summary>Change First Name value.</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cbb_FirstName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Value to test.
            string l_sValueTest = (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnFirstName;

            //Value selected test.
            if (l_sValueTest != string.Empty)
            {
                if (l_sValueTest != null)
                {
                    if (((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLastName == l_sValueTest) ||
                                    ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLogin == l_sValueTest) ||
                                    ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnMail == l_sValueTest))
                    {
                        //Value non unique.
                        (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnFirstName = string.Empty;

                        //User message.
                        MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow(String.Empty, string.Format(Resx.GetLabel(ResxRioManagerGroup.GROUP_MSG_CORRESPONDENCE_AD_RIO_COLUMN_USE), l_sValueTest), MessageBoxButtons.Ok, MessageBoxIcon.Error);
                        L_oMessage.Show();
                    }
                }
            }            
        }

        /// <summary>Change Login value.</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cbb_Login_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Value to test.
            string l_sValueTest = (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLogin;

            //Value selected test.
            if (l_sValueTest != string.Empty)
            {
                if (l_sValueTest != null)
                {
                    if (((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnFirstName == l_sValueTest) ||
                    ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLastName == l_sValueTest) ||
                    ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnMail == l_sValueTest))
                    {
                        //Value non unique.
                        (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLogin = string.Empty;

                        //User message.
                        MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow(String.Empty, string.Format(Resx.GetLabel(ResxRioManagerGroup.GROUP_MSG_CORRESPONDENCE_AD_RIO_COLUMN_USE), l_sValueTest), MessageBoxButtons.Ok, MessageBoxIcon.Error);
                        L_oMessage.Show();
                    }
                }
            }            
        }

        /// <summary>Change Mail value.</summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Cbb_Mail_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Value to test.
            string l_sValueTest = (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnMail;

            //Value selected test.
            if (l_sValueTest != string.Empty)
            {
                if (l_sValueTest != null)
                {
                    if (((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnFirstName == l_sValueTest) ||
                                    ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLogin == l_sValueTest) ||
                                    ((DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnLastName == l_sValueTest))
                    {
                        //Value non unique.
                        (DataContext as GroupSynchronizationTabViewModel).SelectedDisplayADColumnMail = string.Empty;

                        //User message.
                        MessageBoxChildWindow L_oMessage = new MessageBoxChildWindow(String.Empty, string.Format(Resx.GetLabel(ResxRioManagerGroup.GROUP_MSG_CORRESPONDENCE_AD_RIO_COLUMN_USE), l_sValueTest), MessageBoxButtons.Ok, MessageBoxIcon.Error);
                        L_oMessage.Show();
                    }
                }
            }            
        }

        #endregion Event
    }
}